package com.sphd.emanu.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.emanu.R;
import com.sphd.emanu.pojo.order.Order;
import com.sphd.emanu.pojo.order.OrderItems;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Hu
 * @Time 2017/8/7 --11:00.
 * @Email 87683202@qq.com
 */
public class SendAdapter extends BaseQuickAdapter<Order, BaseViewHolder> {


    Context context;
    int state;
    public SendAdapter(@LayoutRes int layoutResId, @Nullable List<Order> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, Order item) {
        RecyclerView itemRecy = helper.getView(R.id.order_list);
        itemRecy.setHasFixedSize(true);
        itemRecy.setLayoutManager(new LinearLayoutManager(context));
        itemRecy.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        OrdersDetailAdapter ordersDetailAdapter = new OrdersDetailAdapter(R.layout.item_order_detail, new ArrayList<OrderItems>(), false);

        itemRecy.setAdapter(ordersDetailAdapter);

        ordersDetailAdapter.setNewData(item.getListOrderItems());

        helper
                .setText(R.id.send_nane_phone, item.getConsignee() + "\t" + item.getPhone())
                .setText(R.id.send_addr, item.getAddress())
                .addOnClickListener(R.id.btn_confirm)
                .setVisible(R.id.btn_confirm,state==0?true:false)
                .setText(R.id.send_money, "运费￥" + item.getFee() + "\t" + "合计￥" + item.getAmount());
    }

    public void setState(int state) {
        this.state=state;
    }
}
